#region

using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;
using Vin.Extension.Framework.Aop;
using Vin.Extension.Framework.Base;
using Vin.Extension.Framework.Constants;
using Vin.Extension.Framework.Login.Dto.List;
using Vin.Extension.Framework.Login.ServiceInterface;
using Vin.Extension.Framework.Monitor.Filters;
using Vin.Tool.AspNetCore.Singleton;
using Vin.Tool.Attributes;

#endregion

namespace Vin.Extension.Framework.Login.Controller.Controllers;

public class SysAccountController : VinFrameworkBaseController
{
    [Inject] private readonly ISysAccountBindService _sysAccountBindService = null!;

    [VinAuthorize, HttpGet("/bind-ways")]
    public async Task<IActionResult> AccountBindWays()
    {
        return Success(await _sysAccountBindService.ListAsync(new SysAccountBindListDto()
        {
            Page = 1,
            PageSize = 100,
            AccountId = AccountId,
        }));
    }

    [VinAuthorize, OperateLog("账号管理", VinBusinessType.Delete), HttpPost("/un-bind")]
    public async Task<IActionResult> UnBind(
        [Required(ErrorMessage = "解绑类型不能为空")] [FromHeader(Name = "Type")]
        string type)
    {
        // TODO 验证密码
        var handler = VinApp.GetRequiredKeyServiceByHttpContext<ILoginService>(type);
        return Success(await handler.UnBindAsync(HttpContext));
    }

    [VinAuthorize, HttpPost("/bind")]
    public async Task<IActionResult> Bind(
        [Required(ErrorMessage = "绑定类型不能为空")] [FromHeader(Name = "Type")]
        string type)
    {
        var handler = VinApp.GetRequiredKeyServiceByHttpContext<ILoginService>(type);
        return Success(await handler.BindAsync(HttpContext));
    }
}